<div class="jobs index">
<h2><?php __('Jobs');?></h2>
<!-- Table Navigation -->
<div class="tablenav">
    <div class="batchactions"></div>
    <?php echo $this->element('pager'); ?>
</div>
<!-- Table Content Area -->
<table id="table_jobs" class="table fixed">
    <thead title="<?php __('Click a column to sort data table'); ?>">
        <tr>
            <th width="3%" class="checkbox" title="<?php __('Click to select/deselect all records'); ?>"><input type="checkbox" class="checkbox"/></th>
            <th width="5%"><?php echo $paginator->sort('id');?></th>
            <th width="20%"><?php echo $paginator->sort('title');?></th>
            <th width="15%"><?php echo $paginator->sort('workplace');?></th>
            <th width="17%"><?php echo $paginator->sort('students_job_count');?></th>
            <th width="12%"><?php echo $paginator->sort('created');?></th>
            <th width="12%"><?php echo $paginator->sort('company_id');?></th>
            <th width="16%" class="actions"><?php __('Actions');?></th>
        </tr>
    </thead>
    <tfoot title="<?php __('Click a column to sort data table'); ?>">
        <tr>
            <th class="checkbox" title="<?php __('Click to select/deselect all records'); ?>"><input type="checkbox" class="checkbox"/></th>
            <th><?php echo $paginator->sort('id');?></th>
            <th><?php echo $paginator->sort('title');?></th>
            <th><?php echo $paginator->sort('workplace');?></th>
            <th><?php echo $paginator->sort('students_job_count');?></th>
            <th><?php echo $paginator->sort('created');?></th>
            <th><?php echo $paginator->sort('company_id');?></th>
            <th class="actions"><?php __('Actions');?></th>
        </tr>
    </tfoot>
    <tbody>
        <?php foreach ($jobs as $i=>$job):
            $class = $i++ % 2 == 0 ? ' class="altrow"' : ''; ?>
        <tr<?php echo $class;?>>
            <td class="checkbox"><input type="checkbox" class="checkbox"/></td>
            <td><?php echo $job['Job']['id']; ?></td>
            <td><?php echo $job['Job']['title']; ?></td>
            <td><?php echo $job['Job']['workplace']; ?></td>
            <td>

                <?php echo $job['Job']['students_job_count']; ?>
                <!-- Print view detail and export links for admins -->
                <?php if($user['group'] != 'student' && $job['Job']['students_job_count']>0): ?>
                <?php echo $html->link(
                    __('(detail)', true),
                    array(
                        'controller'=>'jobs',
                        'action'=>'student',
                        'job'=>$job['Job']['id'],

                        'export' =>false
                    ),

                    array(
                        'title'=>__('Click to view who have applied this job', true)
                    )); ?>

                <?php echo $html->link(
                    __('(Export)', true),
                    array(
                        'controller'=>'jobs',
                        'action'=>'student',
                        'job'=>$job['Job']['id'],

                        'export' =>true
                    ),

                    array(
                        'title'=>__('Click to export student data that has applied for this job', true)

                    )); ?>

                <?php endif; ?>
            </td>
            <td><?php echo date('Y/m/d', strtotime($job['Job']['created'])); ?></td>
            <td><?php echo $html->link(
                $job['Company']['name'],
                array(
                    'controller'=>'companies',
                    'action'=>'view',
                    $job['Company']['id']
                )); ?>
            </td>
            <td class="actions">
                <?php echo $html->link(__('View', true), array('action' => 'view', $job['Job']['id'])); ?>
                <?php if($user['group'] != 'student'): ?>
                    <?php e($html->link(__('Edit', true), array('action' => 'edit', $job['Job']['id']))); ?>
                    <?php e($html->link(__('Delete', true), array('action' => 'delete', $job['Job']['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $job['Job']['id']))); ?>
                <?php else: ?>
                    <?php e($html->link(__('Apply', true), array('controller'=>'students_jobs', 'action' => 'add', $job['Job']['id']))); ?>
                <?php endif; ?>
            </td>
        </tr>
        <?php endforeach; ?>
    <tbody>
</table>
</div>
<!-- If its is student we bind ajax apply else we bind ajax delete -->
<?php if($user['group'] != 'student'): ?>
<div class="actions">
    <ul><li><?php echo $html->link(__('New Job', true), array('action' => 'add')); ?></li></ul>
</div>
<!-- Script for ajax job deletion-->
<script type="text/javascript">
    jQuery(function(){
        // Apply for the job through ajax
        $('table#table_jobs td.actions a[href*=delete]').click($.sme.cbk.ajaxDelete);
    });
</script>
<?php else: ?>
<!-- Script for ajax job apply -->
<script type="text/javascript">
    jQuery(function(){
        // Apply for the job through ajax
        $('table#table_jobs td.actions a[href*=students_jobs]').click($.sme.cbk.ajaxApply);
    });
</script>
<?php endif; ?>